home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / UNIQUE.CPP < prev    next >
Text File  |  1997-05-06  |  862b  |  36 lines

  1.  #include <algorithm>
  2.  #include <vector>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize two vectors.
  10.    //
  11.    int a1[20] = {4, 5, 5, 9, -1, -1, -1, 3, 7, 5,
  12.                  5, 5, 6, 7, 7, 7, 4, 2, 1, 1};
  13.    vector<int> v(a1+0, a1+20), result;
  14.    //
  15.    // Create an insert_iterator for results.
  16.    //
  17.    insert_iterator<vector<int> > ins(result, result.begin());
  18.    //
  19.    // Demonstrate includes.
  20.    //
  21.    cout << "The vector: " << endl << "    ";
  22.    copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
  23.    //
  24.    // Find the unique elements.
  25.    //
  26.    unique_copy(v.begin(), v.end(), ins);
  27.    //
  28.    // Display the results.
  29.    //
  30.    cout << endl << endl << "Has the following unique elements:"
  31.         << endl << "     ";
  32.    copy(result.begin(),result.end(), ostream_iterator<int>(cout," "));
  33.  
  34.    return 0;
  35. }
  36.